Allow the leader election resource lock type to be configurable#1448
Allow the leader election resource lock type to be configurable#1448mprahl wants to merge 1 commit intoopenshift:masterfrom mprahl:leader-election
Conversation
|
/cc deads2k soltysh sttts |
|
Could I please get a review on this PR? |
|
@dgrisonnet could you please provide your thoughts on my last comment? |
|
Okay, the PR is updated. |
|
@dgrisonnet is this good to merge then? |
| // See https://github.com/kubernetes/kubernetes/issues/107454 for | ||
| // details on how to migrate to "leases" leader election. | ||
| // Don't forget the callbacks! | ||
| // TODO: In the next version we should switch to using "leases" |
There was a problem hiding this comment.
@tkashem did you intend to switch the default to leases instead of configmapleases? If so we might want to keep this TODO until the default resource is updated.
There was a problem hiding this comment.
@dgrisonnet and @tkashem I moved the TODO to where the logic for the default resource lock is made. Is this okay with you?
There was a problem hiding this comment.
Yes, actually, that was the goal
we want the following:
- A: a brand new operator being written should us
lease(preferably by default) - B: existing operators who are currently using
configmapsleasesshould uselease(preferably by default) - C: existing operators who have not yet upgraded libray-go for a while (still using
configmaps) should start usingconfigmapsleasesas soon as they upgrade to the latest library-go (we can't have these operators useleaseby default, it will break their upgrade flow)
I am concerned about C - if we don't have any existing operators in C category today then we can safely rename ToLeaderElectionWithConfigmapLease to ToLeaderElectionWithLease and have lease be the default option.
So I would like to know if C is empty today - it can be possible today to count C, maybe by having a test in CI?
or is there a way we can break (static, compile time) these operators in C when they upgrade library-go so they can opt-in? I would like us to be able to avoid these changes if possible, especially if C is empty.
There was a problem hiding this comment.
Leases are not 100% reliable today. It's been a while since the switch I think, I'd simply switch.
There was a problem hiding this comment.
@mprahl can you revise the pr to switch to lease? (disregard C, that means no need to make anything configurable)
There was a problem hiding this comment.
@tkashem in ACM we would like to still have the option for configmapsleases if that's okay. I'd make lease the default though.
There was a problem hiding this comment.
@mprahl yeah, sure, go ahead. (just curious, you have an operator that is currently using configmaps?)
The controllercmd package always utilized a configmapsleases resource lock for leader election, but some client may entirely want to move to leases. This commit keeps the default to configmapsleases but allows it to be configurable of current best practices. Related issues: #1178 https://issues.redhat.com/browse/ACM-2653 Signed-off-by: mprahl <mprahl@users.noreply.github.com>
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: mprahl The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
|
/retest |
|
|
||
| // WithLeaderElectionResourceLock sets the resource lock. If not set, controllercmd.ConfigMapsLeasesResourceLock will | ||
| // be used for backwards compatibility. | ||
| func (b *ControllerBuilder) WithLeaderElectionResourceLock(resourceLock leaderElectionResourceLock) *ControllerBuilder { |
There was a problem hiding this comment.
instead of using the lock as a parameter, can we have two methods?
WithLeaderElectionLeaseResourceLock() *ControllerBuilder
WithLeaderElectionConfigmapLeaseResourceLock() *ControllerBuilder
this way we don't have to have validation around resource lock names and in future we can simply remove WithLeaderElectionConfigmapLeaseResourceLock
| // ToLeaderElectionWithLease returns a "leases" based leader | ||
| // election config that you just need to fill in the Callback for. | ||
| // Don't forget the callbacks! | ||
| func ToLeaderElectionWithLease(clientConfig *rest.Config, config configv1.LeaderElection, component, identity string) (leaderelection.LeaderElectionConfig, error) { |
There was a problem hiding this comment.
we can remove ToLeaderElectionWithLease and restore toLeaderElection to ToLeaderElection
| return fmt.Errorf("%w: %s", ErrInvalidResourceLock, b.leaderElectionResourceLock) | ||
| } | ||
|
|
||
| leaderElection, err := leaderelectionconverter.ToLeaderElectionWithConfigmapLease(leaderConfig, *b.leaderElection, b.componentName, b.instanceIdentity) |
There was a problem hiding this comment.
use proposed eaderelectionconverter.ToLeaderElection(leaderConfig, *b.leaderElection, b.componentName, b.instanceIdentity, b.leaderElectionResourceLock
we can get rid of the switch here
|
|
||
| // LeaderElectionResourceLock sets the resource lock. If not set, controllercmd.ConfigMapsLeasesResourceLock will | ||
| // be used for backwards compatibility. | ||
| LeaderElectionResourceLock leaderElectionResourceLock |
There was a problem hiding this comment.
we need to know whether it's lease or configmapsleases, so can we make it a boolean
// DEPRECATED: at some point everything should uses lease by default
OverrideConfigmapsLeasesResourceLock bool
This will allow new operators to opt in for lease
| WithKubeConfigFile(c.basicFlags.KubeConfigFile, nil). | ||
| WithComponentNamespace(c.basicFlags.Namespace). | ||
| WithLeaderElection(config.LeaderElection, c.basicFlags.Namespace, c.componentName+"-lock"). | ||
| WithLeaderElectionResourceLock(c.LeaderElectionResourceLock). |
There was a problem hiding this comment.
replace it with
builder = builder. WithLeaderElectionConfigmapLeaseResourceLock()
if c.OverrideConfigmapsLeasesResourceLock {
builder = builder. WithLeaderElectionLeaseResourceLock()
}
|
Closing in favor of: |
The controllercmd package always utilized a configmapsleases resource lock for leader election, but some client may entirely want to move to leases. This commit keeps the default to configmapsleases but allows it to be configurable to whatever the
k8s.io/client-go/tools/leaderelection/resourcelock package allows.
Related issues:
#1178
https://issues.redhat.com/browse/ACM-2653